Skip to contentMethod: computeNextMove(int, FGPlayer, FGState, long)
      1: 
2: package de.fhdw.gaming.ipspiel24.fg.strategy;
3: 
4: import java.security.SecureRandom;
5: import java.util.Optional;
6: 
7: import de.fhdw.gaming.ipspiel24.fg.domain.FGPlayer;
8: import de.fhdw.gaming.ipspiel24.fg.domain.FGState;
9: import de.fhdw.gaming.ipspiel24.fg.domain.FGStrategy;
10: import de.fhdw.gaming.ipspiel24.fg.moves.FGMove;
11: import de.fhdw.gaming.ipspiel24.fg.moves.factory.FGMoveFactory;
12: 
13: /**
14:  * Implements {@link FGStrategy} by always saying "no".
15:  */
16: public final class FGmixedFootballStrategy implements FGStrategy {
17: 
18:     /**
19:      * The factory for creating FG moves.
20:      */
21:     private final FGMoveFactory moveFactory;
22:     private final SecureRandom random;
23: 
24:     /**
25:      * Creates an {@link FGmixedFootballStrategy}.
26:      *
27:      * @param moveFactory The factory for creating FG moves.
28:      */
29:     FGmixedFootballStrategy(final FGMoveFactory moveFactory) {
30:         this.moveFactory = moveFactory;
31:         this.random = new SecureRandom();
32:     }
33: 
34:     @Override
35:     public Optional<FGMove> computeNextMove(
36:             final int gameId,
37:             final FGPlayer player,
38:             final FGState state,
39:             final long maxComputationTimePerMove) {
40:•        if (random.nextInt(3) < 2) {
41:             return Optional.of(this.moveFactory.createFootballMove());
42:         } else {
43:             return Optional.of(this.moveFactory.createCinemaMove());
44:         }
45:     }
46: 
47:     @Override
48:     public String toString() {
49:         return FGmixedFootballStrategy.class.getSimpleName();
50:     }
51: }